package com.heima.wemedia.listener;

import com.heima.wemedia.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class DelayAutoScanNewsListener {
    @Autowired
    private WmNewsAutoScanService wmNewsAutoScanService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.auto.news", durable = "true"),
            exchange = @Exchange(name = "delay.direct", delayed = "true"),
            key = "delay_scan_news"
    ))
    public void autoScanNewsDelay(String newsId){
        log.info("接收到消息ID：{}，时间是{}",newsId,new Date().getTime());
        wmNewsAutoScanService.autoScanWmNews(Integer.valueOf(newsId));
    }
}
